<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="${website}resource/admin/css/admin.css" type="text/css" />
<script type="text/javascript" src="${website}resource/js/common_min.js"></script>
<title>Insert title here</title>
<script type="text/javascript">
	var doTd;
	var thisTr;
	$(document).ready(function(){
		var thisTr;
		var doTd;
		var id;
		var cityName;
		var cityId;
		var name;
		var area;
		var postcode;
		var telephone;
		var address;
		var type;
		$(".modify").live("click",function(){
			id = $(this).attr("data");
			cityId = $(this).attr("dataCityId");
			type = $(this).attr("dataType");
			thisTr = $(this).parent().parent();
			doTd = thisTr.find("td:last").html();
			cityNameTd = thisTr.find("td:eq(0)"); cityName = cityNameTd.html();
			nameTd = thisTr.find("td:eq(1)");     name = nameTd.html();
			nameTd.html("<input type='text' class='name' value="+name+" '/>");
			areaTd = thisTr.find("td:eq(2)"); area = areaTd.html();			
			areaTd.html("<input type='text' class='area' value="+area+" '/>");
			postcodeTd = thisTr.find("td:eq(3)"); postcode = postcodeTd.html();			
			postcodeTd.html("<input type='text' class='postcode' value="+postcode+" '/>");
			telephoneTd = thisTr.find("td:eq(4)"); telephone = telephoneTd.html();			
			telephoneTd.html("<input type='text' class='telephone' value="+telephone+" '/>");
			addressTd = thisTr.find("td:eq(5)"); address = addressTd.html();			
			addressTd.html("<input type='text' class='address' value="+address+" '/>");
			$(this).parent().html("<input type='button' class='submit' value='提交' /><input type='button' class='cancel' value='取消' />");
		});
		
		$(".submit").live("click",function(){
			name = $(this).parent().parent().find(".name").val();
			area = $(this).parent().parent().find(".area").val();
			postcode = $(this).parent().parent().find(".postcode").val();
			telephone = $(this).parent().parent().find(".telephone").val();
			address = $(this).parent().parent().find(".address").val();
			data = "tourismOrg.id="+id+"&tourismOrg.cityName="+cityName+"&tourismOrg.cityId="+cityId+"&tourismOrg.name="+name+"&tourismOrg.area="+area+"&tourismOrg.postcode="+postcode+"&tourismOrg.address="+address+"&tourismOrg.telephone="+telephone+"&tourismOrg.type="+type;
			$.ajax({
				type:"post",
				url:"${website}admin/city_ajaxModifyTourismOrg.action",
				data:data,
				success:refreshTr()
			});
		});
		$(".cancel").live("click",function(){
			refreshTr();
		});
		//删除一条信息
		$(".delete").click(function(){
			var id = $(this).attr("data");
			$.ajax({
				url:"${website}admin/city_ajaxDeleteTourismOrg.action?tourismOrgId=" + id,
				type:"post",
				success:removeThisTr($(this))
			});
		});
		function refreshTr()
		{
			thisTr.find("td:eq(1)").html(name);
			thisTr.find("td:eq(2)").html(area);
			thisTr.find("td:eq(3)").html(postcode);
			thisTr.find("td:eq(4)").html(telephone);
			thisTr.find("td:eq(5)").html(address);
			thisTr.find("td:last").html(doTd);
		}
		function removeThisTr(thisLine)
		{
			thisLine.parent().parent().remove();	
		}
	});
</script>
</head>
<body>
<span style="text-align: center">市内旅游机构</span>
	<table>
		<tr>
			 
			<td>城市</td>
			<td>机构名称</td>
			<td>所属地区</td>
			<td>邮编</td>
			<td>电话</td>
			<td>机构地址</td>
			<td>操作</td>
		</tr>
		<c:forEach items="${cityInsideTourismOrgList}" var="inside">
		<tr>
			<td>${inside.cityName}</td>
			<td>${inside.name}</td>
			<td>${inside.area}</td>
			<td>${inside.postcode}</td>
			<td>${inside.telephone}</td>
			<td>${inside.address}</td>
			<td>
				<a href="${website}admin/city_modifyCityTourismOrg.action?id=${inside.id}">修改</a>
				<a class="delete" href="#" data="${inside.id}">删除</a>
			</td>
		</tr>
		</c:forEach>
	</table>
	
	<span style="text-align: center">市外旅游机构</span>
	<table>
		<tr>
			
			<td>城市</td>
			<td>机构名称</td>
			<td>所属地区</td>
			<td>邮编</td>
			<td>电话</td>
			<td>机构地址</td>
			<td>操作</td>
		</tr>
		<c:forEach items="${cityOutsideTourismOrgList}" var="outside">
		<tr>
			<td>${outside.cityName}</td>
			<td>${outside.name}</td>
			<td>${outside.area}</td>
			<td>${outside.postcode}</td>
			<td>${outside.telephone}</td>
			<td>${outside.address}</td>
			<td>
				<a class="modify" href="#" data="${outside.id}" dataCityId="${outside.cityId}" dataType="false">修改</a>
				<a class="delete" href="#" data="${outside.id}">删除</a>
			</td>
		</tr>
		</c:forEach>
	</table>
</body>
</html>